﻿/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-8-13
Description:CustomerList.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class CustomerAdd : System.Web.UI.Page
{

    string TableName = "CustomerList";//表名
    static string SqlWhere = " 1=1 ";//过滤条件
    string GetCountSql = "select count(id)  from CustomerList where " + SqlWhere;
    string SqlTable = "select *  from CustomerList where " + SqlWhere + "  order by id desc ";
    string ReturnPage = "CustomerList.aspx";
    FTchina.SearchQuery.QueryModel qm = new FTchina.SearchQuery.QueryModel();//实例化模型

    protected void Page_Load(object sender, EventArgs e)
    {
        FTchina.basic.CheckAdmin(this);
        FTchina.basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());
        if (!IsPostBack)
        {
            string act = FTchina.basic.FilterSQL(Request["act"]);
            switch (act)
            {
                case "mod":
                    {
                        btnCustomerListOk.Text = "确定修改";
                        txbid.Enabled = false;
                        DisplayData();
                        plop.Visible = true;
                        break;
                    }
                case "del":
                    {
                        DeleteData();
                        break;
                    }
                case "add":
                    {
                        txbid.Text = "0";
                        txbid.Visible = false;
                        plop.Visible = true;//添加修改的表单可以看见
                        break;
                    }
                default:
                    {
                        txbid.Text = "0";
                        txbid.Visible = false;
                        plop.Visible = true;//添加修改的表单看不见
                        break;
                    }

            }
            BindGroup();
            
        }
    }


    protected void BindGroup()
    {
        string sql = "select * from CustomerGroup order by id asc";
        ddlcg.DataSource = FTchina.shujuku.GetDataTable(sql);
        ddlcg.DataTextField = "groupname";
        ddlcg.DataValueField = "id";
        ddlcg.DataBind();

    }
    private void DeleteData()
    {
        FTchina.UImsg.PageRender(FTchina.BLL.CustomerListManager.DeleteCustomerListByid(Convert.ToInt32(FTchina.basic.FilterSQL(Request["id"]))) > 0, HttpContext.Current.Request.Path.ToString());
    }
    private void DisplayData()
    {
        FTchina.Models.CustomerList mCustomerList = FTchina.BLL.CustomerListManager.GetCustomerListByid(Convert.ToInt32(FTchina.basic.FilterSQL(Request["id"])));

        txbid.Text = mCustomerList.Id.ToString();

        txbcustomerName.Text = mCustomerList.CustomerName.ToString();

        this.ddlsex.SelectedValue = mCustomerList.CustormeSex.ToString();

        txbcustomerTel0.Text = mCustomerList.CustomerTel0.ToString();

        txbcustomerTel1.Text = mCustomerList.CustomerTel1.ToString();

        txbcustomerTel2.Text = mCustomerList.CustomerTel2.ToString();

        txbcustomerlandline0.Text = mCustomerList.Customerlandline0.ToString();

        txbcustomerlandline1.Text = mCustomerList.Customerlandline1.ToString();

        txbcustomerlandline2.Text = mCustomerList.Customerlandline2.ToString();

        txbcustomerAddress0.Text = mCustomerList.CustomerAddress0.ToString();

        txbcustomerMeetAddress.Text = mCustomerList.CustomerMeetAddress.ToString();

        txbmemo.Text = mCustomerList.Memo.ToString();
        ddlcg.SelectedValue = mCustomerList.CustomerGroupID.ToString();

        txbcallcount.Text = mCustomerList.Callcount.ToString();

        txbmeetCount.Text = mCustomerList.MeetCount.ToString();

        txblastCallDate.Text = mCustomerList.LastCallDate.ToString();

        txblastMeetDate.Text = mCustomerList.LastMeetDate.ToString();
        txbcustomerWork.Text = mCustomerList.CustomerWork.ToString();
    }

    private void DataModifiy()
    {
        FTchina.Models.CustomerList mCustomerList = new FTchina.Models.CustomerList();

        mCustomerList.Id = Convert.ToInt32(FTchina.basic.FilterSQL(txbid.Text));

        mCustomerList.CustomerName = FTchina.basic.FilterSQL(txbcustomerName.Text);

        mCustomerList.CustormeSex = FTchina.basic.FilterSQL(ddlsex.SelectedValue);

        mCustomerList.CustomerTel0 = FTchina.basic.FilterSQL(txbcustomerTel0.Text);
        if (!FTchina.basic.ValidateMobile(mCustomerList.CustomerTel0))
        {
            FTchina.JS.Alert("手机号码输入错误！");
            return;
        }
        mCustomerList.CustomerTel1 = FTchina.basic.FilterSQL(txbcustomerTel1.Text);

        mCustomerList.CustomerTel2 = FTchina.basic.FilterSQL(txbcustomerTel2.Text);

        mCustomerList.Customerlandline0 = FTchina.basic.FilterSQL(txbcustomerlandline0.Text);

        mCustomerList.Customerlandline1 = FTchina.basic.FilterSQL(txbcustomerlandline1.Text);

        mCustomerList.Customerlandline2 = FTchina.basic.FilterSQL(txbcustomerlandline2.Text);

        mCustomerList.CustomerAddress0 = FTchina.basic.FilterSQL(txbcustomerAddress0.Text);

        mCustomerList.CustomerMeetAddress = FTchina.basic.FilterSQL(txbcustomerMeetAddress.Text);

        mCustomerList.Memo = FTchina.basic.FilterSQL(txbmemo.Text);

        mCustomerList.CustomerGroupID = Convert.ToInt32(ddlcg.SelectedValue);

        mCustomerList.Callcount = Convert.ToInt32(FTchina.basic.FilterSQL(txbcallcount.Text));

        mCustomerList.MeetCount = Convert.ToInt32(FTchina.basic.FilterSQL(txbmeetCount.Text));

        mCustomerList.LastCallDate = Convert.ToDateTime(FTchina.basic.FilterSQL(txblastCallDate.Text));

        mCustomerList.LastMeetDate = Convert.ToDateTime(FTchina.basic.FilterSQL(txblastMeetDate.Text));
        mCustomerList.CustomerWork = FTchina.basic.FilterSQL(this.txbcustomerWork.Text);

        FTchina.UImsg.PageRender(FTchina.BLL.CustomerListManager.ModifyCustomerListByid(mCustomerList) > 0);

    }
    private void DataAdd()
    {


        FTchina.Models.CustomerList mCustomerList = new FTchina.Models.CustomerList();

        mCustomerList.Id = Convert.ToInt32(FTchina.basic.FilterSQL(txbid.Text));

        mCustomerList.CustomerName = FTchina.basic.FilterSQL(txbcustomerName.Text);

        mCustomerList.CustormeSex = ddlsex.SelectedValue;

        mCustomerList.CustomerTel0 = FTchina.basic.FilterSQL(txbcustomerTel0.Text);
        if (!FTchina.basic.ValidateMobile(mCustomerList.CustomerTel0))
        {
            FTchina.JS.Alert("手机号码输入错误！");
            return;
        }
        mCustomerList.CustomerTel1 = FTchina.basic.FilterSQL(txbcustomerTel1.Text);

        mCustomerList.CustomerTel2 = FTchina.basic.FilterSQL(txbcustomerTel2.Text);

        mCustomerList.Customerlandline0 = FTchina.basic.FilterSQL(txbcustomerlandline0.Text);

        mCustomerList.Customerlandline1 = FTchina.basic.FilterSQL(txbcustomerlandline1.Text);

        mCustomerList.Customerlandline2 = FTchina.basic.FilterSQL(txbcustomerlandline2.Text);

        mCustomerList.CustomerAddress0 = FTchina.basic.FilterSQL(txbcustomerAddress0.Text);

        mCustomerList.CustomerMeetAddress = FTchina.basic.FilterSQL(txbcustomerMeetAddress.Text);

        mCustomerList.Memo = FTchina.basic.FilterSQL(txbmemo.Text);

        mCustomerList.CustomerGroupID = Convert.ToInt32(ddlcg.SelectedValue);

        mCustomerList.Callcount = 0;

        mCustomerList.MeetCount = 0;

        mCustomerList.LastCallDate = new DateTime(1910, 1, 1);

        mCustomerList.LastMeetDate = new DateTime(1910, 1, 1);
        mCustomerList.CustomerWork = FTchina.basic.FilterSQL(this.txbcustomerWork.Text);


        FTchina.UImsg.PageRender(FTchina.BLL.CustomerListManager.AddCustomerList(mCustomerList) > 0);
    }


    protected void btnCustomerListOk_Click(object sender, EventArgs e)
    {
        if (btnCustomerListOk.Text == "确定修改") DataModifiy();
        else DataAdd();
    }

 


}






